<?php
include_once($_SERVER['DOCUMENT_ROOT']."/config.php");
include_once($gDOCUMENT_ROOT_SYSTEM.'include/dao/country.php');
include_once($gDOCUMENT_ROOT_SYSTEM.'include/dao/country_name_translation.php');
class countryAction
{
	private $country;
	private $country_name_translation;
	function __construct()
	{
		$this->country = new country();
		$this->country_name_translation = new country_name_translation();
	}
	public function AddFilmBluRay($data)
	{
		try
		{
			$film_id = $this->film_release_on_blu_ray->insert($data);
		}
		catch(Exception $e)
		{
			//echo 'Message: ' .$e->getMessage();
			return false;
		}
	}
	
	public function getCountryIdAndName($first_tag)
	{
		try
		{
			$column = array('country_id','en-US','zh-Hans-CN');
			$result = $this->country_name_translation->select('',$column);
			$id_name = array();
			foreach($result as $row)
			{
				$id_name[$row['country_id']] = $row['zh-Hans-CN'].'（'.$row['en-US'].'）';
			}
			return $id_name;
		}
		catch(Exception $e)
		{
			//echo 'Message: ' .$e->getMessage();
			return false;
		}
	}
	
	public function getCountryCodeAndName($first_tag='zh-Hans-CN',$second_tag='en-US')
	{
		try
		{
			$column = array('id','code');
			$id_code = $this->country->select('',$column);
		}
		catch(Exception $e)
		{
			//echo 'Message: ' .$e->getMessage();
			return false;
		}
		
		try
		{
			$column = array('country_id',$first_tag,$second_tag);
			$id_name = $this->country_name_translation->select('',$column);
		}
		catch(Exception $e)
		{
			//echo 'Message: ' .$e->getMessage();
			return false;
		}
		
		foreach($id_code as $one_id_code)
		{
			foreach($id_name as $one_id_name)
			{
				if($one_id_name['country_id']==$one_id_code['id'])
				{
					$tag_name[$one_id_code['code']] = $one_id_name[$first_tag].'（'.$one_id_name[$second_tag].'）';
				}
			}
		}
		
		return $tag_name;
	}
	
	function getCountryNameByCode($code,$first_tag='zh-Hans-CN',$second_tag='en-US')
	{
		try
		{
			$where = array('code'=>$code);
			$column = array('id'=>$id,'code'=>$code);
			$id_code = $this->country->select($where,$column);
		}
		catch(Exception $e)
		{
			//echo 'Message: ' .$e->getMessage();
			return false;
		}
		
		try
		{
			$where = array('country_id'=>$id_code['id']);
			$column = array($first_tag,$second_tag);
			$name = $this->country_name_translation->select($where,$column);
		}
		catch(Exception $e)
		{
			//echo 'Message: ' .$e->getMessage();
			return false;
		}
		
		return $name;
	}
	
	public function getFilmBluRayByFilmId($film_id,$column='*')
	{
		try
		{
			$blu_ray = $this->film_release_on_blu_ray->getByFilmId($film_id,$column);
			return $blu_ray;
		}
		catch(Exception $e)
		{
			//echo 'Message: ' .$e->getMessage();
			return false;
		}
	}
}

?>
